// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.components;

import java.util.Date;

import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.annotations.AfterRender;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.SetupRender;

/**
 * 一个类似T4中的Shell组件,包含当前页面的名称和创建时间
 * @author <a href=mailto:Ghostbb@bjmaxinfo.com>Ghostbb</a>
 * @version $Revision$
 * @since 0.0.3
 */
public class Shell {
	
	@Inject
	private ComponentResources componentResources;
	
	private long _renderBeginTime;
	
	/**
	 * 默认的构造方法
	 */
	public Shell(){
		
	}
	
	@SetupRender
	public void beginTime(){
		_renderBeginTime = System.currentTimeMillis();		
	}
	
	@BeginRender
	public void renderComment(MarkupWriter writer){
		org.apache.tapestry.runtime.Component page = componentResources.getPage();
		writer.comment("Page:"+page.getComponentResources().getPageName());
		writer.comment("Generated:"+new Date());
	}
	
	@AfterRender
	public void afterTime(MarkupWriter writer){
		long endRenderTime = System.currentTimeMillis();
		long renderTime = endRenderTime - _renderBeginTime;
		writer.comment("Render Time:"+renderTime+"ms");
	}
}
